import re
import os


route_n_result = os.popen('route -n').read()
# print(route_n_result)

"""
str = """
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.67.2    0.0.0.0         UG    100    0        0 ens33
192.168.10.0    0.0.0.0         255.255.255.0   U     101    0        0 ens37
192.168.67.0    0.0.0.0         255.255.255.0   U     100    0        0 ens33
"""
"""

route_split = str.split('\n')

route_split_ip = route_split[2:-1]

for x in route_split_ip:
    y = x.split()
    if y[3] == 'UG':
        print('网关为:',y[1])


"""
网关为: 192.168.67.2
"""